package com.company.project.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.service.HealthCertificateInquiryService;
import com.company.project.vo.req.HealthCertificateQueryVO;
import com.company.project.vo.resp.HealthCertificateQueryResultDTO;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.company.project.common.utils.DataResult;

import com.company.project.entity.EJkzGrdjxxEntity;
import com.company.project.service.EJkzGrdjxxService;

import javax.annotation.Resource;


/**
 * ${comments}
 *
 * @author liuhui
 * @date 2020-11-13 15:50:42
 */
@Api(tags = "体检基本信息")
@RestController
@RequestMapping("/jkz/jbxx")
public class EJkzGrdjxxController {
    @Resource
    private EJkzGrdjxxService eJkzGrdjxxService;
    @Resource
    private HealthCertificateInquiryService healthCertificateInquiryService;

    /**
     * 跳转到页面
     */
    @GetMapping("/index/eJkzGrdjxx")
    public String eJkzGrdjxx() {
        return "ejkzgrdjxx/list";
    }

    @ApiOperation(value = "新增")
    @PostMapping("eJkzGrdjxx/add")
    @RequiresPermissions("eJkzGrdjxx:add")
    @ResponseBody
    public DataResult add(@RequestBody EJkzGrdjxxEntity eJkzGrdjxx) {
        eJkzGrdjxxService.save(eJkzGrdjxx);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("eJkzGrdjxx/delete")
    @RequiresPermissions("eJkzGrdjxx:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        eJkzGrdjxxService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("eJkzGrdjxx/update")
    @RequiresPermissions("eJkzGrdjxx:update")
    @ResponseBody
    public DataResult update(@RequestBody EJkzGrdjxxEntity eJkzGrdjxx) {
        eJkzGrdjxxService.updateById(eJkzGrdjxx);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("eJkzGrdjxx/listByPage")
    @RequiresPermissions("eJkzGrdjxx:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody EJkzGrdjxxEntity eJkzGrdjxx) {
        Page page = new Page(eJkzGrdjxx.getPage(), eJkzGrdjxx.getLimit());
        LambdaQueryWrapper<EJkzGrdjxxEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(EJkzGrdjxxEntity::getId, eJkzGrdjxx.getId());
        IPage<EJkzGrdjxxEntity> iPage = eJkzGrdjxxService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "查询上传到省里体检数据")
    @GetMapping("healthCertificateInquiry")
    @RequiresPermissions("eJkzGrdjxx:list")
    @ResponseBody
    public List<HealthCertificateQueryResultDTO> healthCertificateInquiry(@ApiParam(value = "用户身份证号",required = true) @RequestParam String idCard) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - 10);
        Date today = calendar.getTime();
        HealthCertificateQueryVO queryVO = new HealthCertificateQueryVO();
//        queryVO.setTjxxId(idCard);
//        queryVO.setStartTime(today);
        return healthCertificateInquiryService.healthCertificate(queryVO);
    }

}
